﻿@using eLoan.Models;
@model UserListModel

@{
    ViewBag.Title = "Users";
}

<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-lg-10">
        <h2>Users</h2>
        <ol class="breadcrumb">
            <li>
                Administration
            </li>
            <li class="active">
                <strong>Users</strong>
            </li>
        </ol>
    </div>
    <div class="col-lg-2"></div>
</div>

@using (Html.BeginForm("RefreshUsers", "Administration", FormMethod.Post, new { id = "saveForm" }))
{
    
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-10">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <a href="@Url.Action("AddEdit", "User")" class="btn btn-primary">Add a new user</a>
                    <div class="ibox-tools">
                        @Html.CheckBoxFor(m => Model.ExcludeInactive, new { @onchange="Refresh();" })
                        &nbsp;&nbsp;
                        @Html.LabelFor(m => Model.ExcludeInactive)
                        <button id="btnRefresh" type="submit" style="display:none" ></button>
                    </div>
                </div>
                
                <div class="ibox-content">
                    <div class="scrollable">
                        <table class="table table-bordered">
                            <thead>
                                <tr>
                                    <th>User Name</th>
                                    <th>Branch Name</th>
                                    <th>Role</th>
                                    <th style="width:100px">Is Active</th>
                                    <th></th>
                                </tr>
                            </thead>
                            <tbody>
                                @for (var i = 0; i < Model.Users.Count(); i++)
                                {
                                    <tr>
                                        <td>@Html.DisplayFor(m => Model.Users[i].User.UserName)</td>
                                        <td>@Html.DisplayFor(m => Model.Users[i].BranchName)</td>
                                        <td>@Html.DisplayFor(m => Model.Users[i].RoleName)</td>
                                        <td style="text-align:center">@Html.DisplayFor(m => Model.Users[i].User.IsActive)</td>
                                        <td>@Html.ActionLink("Edit", "AddEdit", "User", null, null, null, new { id = Model.Users[i].User.ID }, null)</td>
                                    </tr>
                                }
                            </tbody>
                        </table>
                    </div>        
                </div>
            </div>

        </div>
    </div>
</div>

}
@section Styles {
    @Styles.Render("~/Content/plugins/dataTables/dataTablesStyles")
<style>
    .scrollable {
        height: 400px;
        overflow-y: scroll;
        border: solid 1px #EBEBEB;
    }
</style>
}

@section Scripts {

    <script type="text/javascript">

        function Refresh() {
            document.getElementById('btnRefresh').click();
        }

    </script>

}